package com.douqu.game.activity.web.controller;

import com.douqu.game.activity.GameServer;
import com.douqu.game.activity.database.mapper.ServerMapper;
import com.douqu.game.activity.manager.ActivityCampManager;
import com.douqu.game.core.database.model.MergeModel;
import com.douqu.game.core.e.ReturnMessage;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.web.response.BaseResponseDto;
import com.douqu.game.core.web.response.ErrorResponseDto;
import com.douqu.game.core.web.response.SuccessResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Author : bean
 * 2017-07-06 15:55
 */
@RestController
@RequestMapping(value = "/server")
public class ServerController {

    @RequestMapping(value = "/test", produces = "application/json;charset=UTF-8")
    public BaseResponseDto test()
    {
        LogUtils.info("测试HTTP接口成功 ------->");

        return new SuccessResponseDto();
    }


    @Autowired
    private ServerMapper serverMapper;

    @RequestMapping(value = "/modifyServerInfo", produces = "application/json;charset=UTF-8")
    public BaseResponseDto modifyServerInfo(Integer id)
    {
        if(id == null)
            return new BaseResponseDto(ReturnMessage.PARAM_ERROR);

        GameServer.getInstance().reloadServerModel(serverMapper.getServerById(id));

        return new SuccessResponseDto();
    }

//    @RequestMapping(value = "/updateServers" ,produces = "application/json;charset=UTF-8")
//    public BaseResponseDto updateServers(@RequestBody MergeModel mergeModel){
//        ActivityCampManager activityCampManager = GameServer.getInstance().getActivityCampManager();
//        //获取所有报名 排行的玩家设置他们的serverid 发生变化
//        try {
//            activityCampManager.updatePleyerServerId(mergeModel);
//        } catch (Exception e) {
//            e.printStackTrace();
//            LogUtils.errorException(e);
//            return new ErrorResponseDto("修改阵营战玩家服务器id失败");
//        }
//        return new SuccessResponseDto();
//    }
}
